package sxkyxt.kjyxgs.cn.ishop_gather_uploading_android;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;


import java.util.List;
import java.util.Map;


public class Photos_Gv_Report_Adapter extends BaseAdapter {

    private Map<Integer, String> mHashMap;
    private Context c;
    private List<Integer> list_key;
    private ImageWork mImageWork;

    public Photos_Gv_Report_Adapter(Map<Integer, String> mHashMap, Context c,
                                    List<Integer> list_key) {
        super();
        this.mHashMap = mHashMap;
        this.c = c;
        this.list_key = list_key;
        mImageWork = new ImageWork(c);
        // toDataKey();
    }

    // private void toDataKey() {
    // Iterator<Integer> iter = mHashMap.keySet().iterator();
    // while (iter.hasNext()) {
    // list_key.add(iter.next());
    // }
    // }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return list_key.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        // return mHashMap.get(key);
        return mHashMap.get(list_key.get(position));
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;

        if (convertView == null) {

            viewHolder = new ViewHolder();
            convertView = View.inflate(c, R.layout.image_gv_photos, null);
            viewHolder.imageView = (ImageView) convertView
                    .findViewById(R.id.gv_image_report);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        mImageWork.loadImage(mHashMap.get(list_key.get(position)),
                viewHolder.imageView);


        return convertView;
    }

    class ViewHolder {
        ImageView imageView;
    }
}
